fn ZE_Cam cam objs =
(
local max2, fov, asp, v -- declare local variables
-- define a function that returns the maximum value
-- of a set of values in an array
fn maxof vals = (local v=vals[1]; for v1 in vals do (if v1 > v do v=v1);v)
fov=0 -- initialize the fov value
asp=(renderWidth as float)/renderHeight -- calculate the renderer's image aspect ratio
in coordsys cam -- work in coordinate system of the camera
(
for obj in objs where obj != cam do -- loop across all objects except the camera
(
if obj.min.z >=0 do continue -- if object is behind camera, skip it
-- get max value of the object's bounding box, correcting for the image aspect ratio
-- in the y values
v = maxof #((abs obj.max.x),(abs obj.min.x),(abs (obj.max.y*asp)),(abs (obj.min.y*asp)))
fov = maxof #(fov,(2*atan(-v/obj.min.z))) -- increase fov if needed
)
)
cam.fov=fov -- set the camera's fov to the new fov value
)
-- test bed --
cam=$CenterCam -- specify the camera to "zoom extent all" on
ZE_Cam cam $* -- call the function, passing the camera and an object set containing all objects